package games.padinvaders;


import utils.RandomNumber;

import graphics.Sprite2D;
import hardware.Display2D;



public class DefenderProjectile extends Sprite2D {




private static final int SPEED_LASER=10;
private static final int SPEED_MISSLE=20;

private int movieCounter;
private int movieCounterMax=10;

private int damage;



public static final int TYPE_NONE	= 0;  
public static final int TYPE_LASER	= TYPE_NONE+1;  
public static final int TYPE_MISSLE = TYPE_LASER+1;
//private static final int TYPE_DOUBLE



public void init()
{
	visible=false;
	xPos=0;
	yPos=1;
	movieCounter=0;
}


public void fire(int xPos,int type)
{
	visible=true;
	this.xPos=xPos;
	yPos=1;
	movieCounter=0;
	
	switch (type)
		{
		case TYPE_LASER:
			movieCounterMax=SPEED_LASER;
			movieCounter=SPEED_LASER;
		break;

		
		case TYPE_MISSLE:
			movieCounterMax=SPEED_MISSLE;
			movieCounter=SPEED_MISSLE;
		break;
		
		}
	
}




public void draw()
{
	short color;
	
	/*
	color=(short) (RandomNumber.get() &0x44);
	color+=0x88;
	*/
	if (visible)
		{
		Display2D.setPixel((byte)xPos,(byte) yPos, (short) 0x8f);
		}
}
	




public void move()
{
	
	if (!visible)
		return;
	
	if (movieCounter>movieCounterMax)
		{
		yPos++;
		
		if (yPos>Display2D.getRowCount()) 
			{
			visible=false;
			}
		}
		else
			{
			movieCounter++;
			}
}






public int checkDamage(int victimXPos,int victimYPos)
{
	int damage;
	

	
	if (!visible)
		return(0);
	

	if ((xPos==victimXPos) && (yPos==victimYPos))
		return(5);

	return(0);
}



public void kill()
{
	visible=false;
	xPos=-1;
	yPos=-1;
}

}
